package com.forum.model.pojo;

import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "forumuser")
@SequenceGenerator(name = "sequence", sequenceName = "forumuser_id_seq", allocationSize = 1)
public class ForumUser {
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence")
	@Column(name = "id")
	private Long id;
	
	@OneToMany(fetch = FetchType.LAZY)
	@Cascade(CascadeType.ALL)
	@JoinColumn(name = "postowner")
	private List<Post> posts;
	
	@Column(name = "loginname", nullable = false, unique = true)
	private String loginName;
	
	@Column(name = "fname", nullable = false)
	private String firstName;
	
	@Column(name = "lname")
	private String lastName;
	
	@Column(name = "country")
	private String country;
	
	@Column(name = "city")
	private String city;
	
	@Column(name = "email")
	private String email;
	
	@Column(name = "avatarimage")
	private String avatarImage;
	
	@Column(name = "signature")
	private String signature;
	
	@Column(name = "shortbio")
	private String shortBio;
	
	@Column(name = "birthdate")
	private Date birthDate;
	
	@Column(name = "rank")
	private char rank;
	
	@Column(name = "gender")
	private char gender;
	
	@Column(name = "postcount")
	private int postCount;
	
	@Column(name = "passhash", nullable = false)
	private String passHash;
	
	public ForumUser() {this.posts = new ArrayList<Post>();}
	
	public ForumUser(String loginName, String firstName, String passHash) {
		this.loginName = loginName;
		this.firstName = firstName;
		this.passHash = passHash;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public List<Post> getPosts() {
		return posts;
	}

	public String getAvatarImage() {
		return avatarImage;
	}

	public void setAvatarImage(String avatarImage) {
		this.avatarImage = avatarImage;
	}

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	public String getShortBio() {
		return shortBio;
	}

	public void setShortBio(String shortBio) {
		this.shortBio = shortBio;
	}
	
	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(int day, int month, int year) {
		this.birthDate = new GregorianCalendar(year, month, day).getTime();
	}

	public char getRank() {
		return rank;
	}

	public void setRank(char rank) {
		this.rank = rank;
	}

	public char getGender() {
		return gender;
	}

	public void setGender(char gender) {
		this.gender = gender;
	}

	public int getPostCount() {
		return postCount;
	}

	public void setPostCount(int postCount) {
		this.postCount = postCount;
	}
	
	public String getPassHash() {
		return passHash;
	}

	public void setPassHash(String passHash) {
		this.passHash = String.valueOf(passHash.hashCode());
	}
}